package org.example.hello5_routingKey_topic;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class RoutingTopicCoustmer {

    /**
     * 接收第一个队列里的信息
     * *匹配路由键的一个词
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(   //把队列和交换机进行绑定
            value=@Queue(value = "topic_queue1", durable = "true", autoDelete = "false"),     //绑定队列
            key = {"user.*"},
            exchange = @Exchange(name = "topic_exchange",type= ExchangeTypes.TOPIC)   //绑定交换机
    ))
    public void receive1(String message){
        System.out.println("user.*-消费者【1】接收到消息"+message);
    }


    /**
     * 接收第二个队列里的信息
     * #号匹配路由键的一个或多个词
     * @param message
     */
    @RabbitListener(bindings = @QueueBinding(   //把队列和交换机进行绑定
            value=@Queue(value = "topic_queue2", durable = "true", autoDelete = "false"),     //绑定队列
            key = {"user.#"},
            exchange = @Exchange(name = "topic_exchange",type= ExchangeTypes.TOPIC)   //绑定交换机
    ))
    public void receive2(String message){
        System.out.println("user.#-消费者【2】接收到消息"+message);
    }
}

